package cn.edu.fzu.homemaking.controller;

import cn.edu.fzu.homemaking.api.SsoApi;
import cn.edu.fzu.homemaking.domain.entity.User;
import cn.edu.fzu.homemaking.service.CusFaceService;
import cn.edu.fzu.homemaking.util.ResultUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import cn.edu.fzu.homemaking.web.Result;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Api(tags = "用户信息管理")
@RestController
@RequestMapping("/api/user")
public class UserController {

    @Resource
    private SsoApi         ssoApi;
    @Resource
    private CusFaceService cusFaceService;

    @ApiOperation(value = "获取本人信息", httpMethod = "GET")
    @GetMapping("auth/getInfo")
    public Result getInfo() {
        Result userInfo = ssoApi.getUserInfo();
        return new Result(ResultUtil.parseValue(userInfo, User.class));
    }


    @ApiOperation(value = "个人修改基本信息")
    @ApiImplicitParams({ @ApiImplicitParam(name = "phone", value = "手机号"),
            @ApiImplicitParam(name = "address", value = "家庭地址"),
            @ApiImplicitParam(name = "faceUrl", value = "人脸照片"),
            @ApiImplicitParam(name = "email",value = "电子邮件") })
    @GetMapping("auth/updateInfo")
    public Result updateInfo(String phone, String address, String faceUrl, String email) {
        ssoApi.updateInfo(phone, address, faceUrl, email);
        return Result.SUCCESS;
    }


    @ApiOperation(value = "登出接口")
    @GetMapping("/logout")
    public Result logout() {
        return ssoApi.logout();
    }


    @ApiOperation(value = "上传人脸接口")
    @PostMapping("/auth/uploadFace")
    public Result upload(MultipartHttpServletRequest request) {
        return new Result(cusFaceService.uploadFace(request.getFile("file")));
    }

}
